home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Over 1,000 Windows 95 Programs
/
Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso
/
1256
/
cppredoc.c_
/
cppredoc.c
Wrap
C/C++ Source or Header
|
1997-04-18
|
10KB
|
266 lines
/* EasyCODE(C++) V5.1 02.03.1995 18:29:03 */
/* EasyCODE O
If=vertical
LevelNumbers=no
LineNumbers=no
ScreenFont=Courier New,,80,9220,-11,0,400,0,0,0,0,0,0,3,2,1,49
PrinterFont=Courier New,,80,17414,-34,0,400,0,0,0,0,0,0,3,2,1,49
LastLevelId=9 */
/* EasyCODE ( 1
cppredoc.c */
/* EasyCODE ( 9
Includes, Defines, Globals */
#include "conv.h" // include header files
#include "tabledef.h"
#include <stdio.h>
#include "c_filt.h"
#define ERR_KEYWORD "Illegal keyword" // define error messages
#define ERR_EOF "Unexpected EOF"
#define ERR_NO_KEYWORD "No keyword in line"
#define ERR_COMMENT1 "Comment not closed"
#define ERR_COMMENT2 "Unexpected end of comment"
#define USAGEMSG "Usage: %s inputfile outputfile\n"
FILE *infile, *outfile; // variables declaration
BOOL bEnd, bInBlockOrLevelOrFunction;
char delimiter[2];
int key_num, line_nr, Nullvalue;
/* EasyCODE ) */
/* EasyCODE ( 7
convert */
/* EasyCODE F */
void convert(int key_nr)
/**************************************************************************************
** Function : convert
** Parameters : Key_nr of keyword
** Return value : none
** Purpose: Create new ETF file, containing only comments and constructs but no
** statements. Conversion is done line by line using the function
** CommentFilter to get the comments.
**************************************************************************************/
{
switch (key_nr
/* Processing depends on keyword */)
{
case ETF_EASYCODE /* Keyword: EasyCode */:
case ETF_SHORTINFO /* Keyword: ShortInfo */:
case ETF_ENDSHORTINFO /* Keyword: EndShortInfo */:
case ETF_OPTIONS /* Keyword: Options */:
case ETF_IFLAYOUT /* Keyword: IfLayout */:
case ETF_LEVELNUMBERS /* Keyword: LevelNumbers */:
case ETF_LINENUMBERS /* Keyword: LineNumbers */:
case ETF_CONSTRUCTNUMBERS /* Keyword: ConstructNumbers */:
case ETF_SCREENFONT /* Keyword: ScreenFont */:
case ETF_PRINTERFONT /* Keyword: PrinterFont */:
case ETF_LASTLEVELID /* Keyword: LastLevelId */:
case ETF_ENDOPTIONS /* Keyword: EndOptions */:
case ETF_IF /* Keyword: if */:
case ETF_THEN /* Keyword: Then */:
case ETF_ELSE /* Keyword: Else */:
case ETF_ENDIF /* Keyword: EndIf */:
case ETF_WHILE /* Keyword: While */:
case ETF_WHILEBODY /* Keyword: WhileBody */:
case ETF_ENDWHILE /* Keyword: EndWhile */:
case ETF_BLOCKBODY /* Keyword: BlockBody */:
case ETF_ENDBLOCK /* Keyword: EndBlock */:
case ETF_LEVELBODY /* Keyword: LevelBody */:
case ETF_ENDLEVEL /* Keyword: EndLevel */:
case ETF_FOR /* Keyword: For */:
case ETF_FORBODY /* Keyword: ForBody */:
case ETF_ENDFOR /* Keyword: EndFor */:
case ETF_DOWHILE /* Keyword: DoWhile */:
case ETF_UNTIL /* Keyword: Until */:
case ETF_ENDDOWHILE /* Keyword: EndDoWhile */:
case ETF_BREAK /* Keyword: Break */:
case ETF_CONTINUE /* Keyword: Continue */:
case ETF_CSWITCH /* Keyword: CSwitch */:
case ETF_CSWITCHBODY /* Keyword: CSwitchBody */:
case ETF_ENDCSWITCH /* Keyword: EndCSwitch */:
case ETF_CCASEBRANCH /* Keyword: CCaseBranch */:
case ETF_CCASEBRANCHBODY /* Keyword: CCaseBranchBody */:
case ETF_ENDCCASEBRANCH /* Keyword: EndCCaseBranch */:
case ETF_DEFAULT /* Keyword: Default */:
case ETF_ENDDEFAULT /* Keyword: EndDefault */:
case ETF_RETURN /* Keyword: Return */:
case ETF_ENDRETURN /* Keyword: EndReturn */:
case ETF_CLASSBODY /* Keyword: ClassBody */:
case ETF_ENDCLASSBODY /* Keyword: EndClassBody */:
case ETF_ENDCLASS /* Keyword: EndClass */:
case ETF_PRIVATE /* Keyword: Private */:
case ETF_PUBLIC /* Keyword: Public */:
case ETF_PROTECTED /* Keyword: Protected */:
case ETF_FUNCTIONBODY /* Keyword: FunctionBody */:
case ETF_ENDFUNCTION /* Keyword: EndFunction */:
StoreLine( inbuf, outfile);
/* All lines before are written unmodified to the output file */
break;
case ETF_CLASS /* Keyword: Class */:
case ETF_FUNCTION /* Keyword: Function */:
case ETF_LEVEL /* Keyword: Level */:
case ETF_BLOCK /* Keyword: Block */:
StoreLine( inbuf, outfile);
bInBlockOrLevelOrFunction = TRUE;
/* Store keyword and set flag bInBlockOrLevelOrFunction because
following text shall not be filtered. */
break;
case ETF_LINE /* Keyword: Line */:
if (bInBlockOrLevelOrFunction
/* If within block header or level header */)
{
StoreLine( inbuf, outfile);
/* Store line unmodified */
}
else
{
/* Line has to be filtered */
switch (CommentFilter( &Nullvalue, outfile)
/* Call function for filtering comments */)
{
case ERROR_COMMENT
/* Error filtering comments */:
err_msg( line_nr, ERR_COMMENT2);
/* Print error message */
break;
case ERROR_EOF
/* Unexpected EOF */:
err_msg( line_nr, ERR_EOF);
break;
default:
break;
}
}
break;
case ETF_TEXT /* Keyword: Text */:
StoreLine( inbuf, outfile);
/* Save keyword */
break;
case ETF_ENDTEXT /* Keyword: EndText */:
if (bInBlockOrLevelOrFunction
/* If within block header or level header */)
{
bInBlockOrLevelOrFunction = FALSE;
/* At end of block header or level header flag has to be reset */
}
if ((bInBlockComment) || (bInLineComment)
/* If within block header or level header */)
{
err_msg(line_nr, ERR_COMMENT1);
/* Error message because comment is not finished */
}
StoreLine( inbuf, outfile);
/* Save keyword */
break;
case ETF_DUMMY /* Keyword: Dummy */:
if (bInBlockOrLevelOrFunction
/* Dummy in block header or level header */)
{
bInBlockOrLevelOrFunction = FALSE;
/* Reset flag for comment filtering */
}
StoreLine( inbuf, outfile);
/* Save Dummy keyword */
break;
case NO_KEYWORD /* Keyword: NO_KEYWORD */:
err_msg( line_nr, ERR_NO_KEYWORD);
exit(1);
/* Error message and program termination if line without keyword */
break;
case ERROR_KEYWORD /* Keyword: ERROR_KEYWORD */:
err_msg( line_nr, ERR_KEYWORD);
exit(1);
/* Error message and program termination if invalid keyword */
break;
case EOF_KEYWORD /* Keyword: EOF_KEYWORD */:
err_msg( line_nr, ERR_EOF);
exit(1);
/* Error message and program termination if unexpected EOF */
break;
default:
err_msg(line_nr, ERR_KEYWORD);
exit(1);
/* Error message and program termination if unknown keyword */
break;
}
}
/* EasyCODE ) */
/* EasyCODE ( 8
main */
/* EasyCODE F */
/*****************************************************************************************
** Function: main
** Parameters: Inputfile und Outputfile
*****************************************************************************************/
main(argc,argv)
int argc;
char *argv[];
{
int Nullvalue = 0;
int level_nr = 0; // Counter for open levels
bInBlockOrLevelOrFunction = FALSE; // Flag indicating position within block header or level header
if (argc != 3
/* Number of arguments not 3 */)
{
fprintf(stderr, USAGEMSG, argv[0]);
exit(1);
/* error message */
}
if (strcmp(argv[1], argv[2]) == 0
/* Same input file and output file */)
{
fprintf(stderr, USAGEMSG, argv[0]);
exit(1);
/* error message */
}
line_nr = 0; // Initialize line number
/* EasyCODE - */
infile = OpenInput(argv[1]); // Open input file
outfile = OpenOutput(argv[2]); // Open output file
while (!(bEnd = ReadLine(inbuf, infile))
/* not EOF */)
{
++line_nr; // Count lines
/* EasyCODE - */
convert( key_num = GetKeyword( delimiter, i_buf));
/* Call conversion function */
switch (key_num
/* Last keyword */)
{
case ETF_LEVEL /* Keyword: Level */:
level_nr++; // Increment level counter
break;
case ETF_ENDLEVEL /* Keyword: EndLevel */:
level_nr--; // Decrement level counter
break;
}
}
if (key_num != ETF_ENDLEVEL
/* EOF but last keyword not ENDLEVEL */)
{
err_msg( line_nr, ERR_EOF );
/* error message */
}
else
{
if (level_nr != 0
/* Level depth not 0 */)
{
err_msg( line_nr, ERR_EOF);
/* error message */
}
}
CloseFile(infile); // Close input file
CloseFile(outfile); // Close output file
}
/* EasyCODE ) */
/* EasyCODE ) */